<?php $this->JQuery()->javascriptCaptureStart()?>

    $j(document).ready(function(){
    	var def_text_address = "e.g.: 8 Lucky Building, 88 Caine Road, Central";
    	var def_text_website = "http://";
    	
    	if ($j.browser.msie) {
	        $j('.logo_uploader_ie').show();
	        $j('#container_uploader1').hide();
	        $j('.logo_preview').hide();
	    } else {
	        $j('.logo_uploader_ie').hide();
	        $j('#container_uploader1').show();
	        $j('.logo_preview').show();
	    }
    /*	
		if($j('#company_mail_address').val() == ""){
			$j('#company_mail_address').val(def_text_address);
		}
	*/	
		if($j('#company_website').val() == ""){
			$j('#company_website').val(def_text_website);
		}
	/*	
		$j('#company_mail_address').focus(function() {
		  	if($j('#company_mail_address').val() == def_text_address){
				$j('#company_mail_address').val("");
			}
		});	
*/
    	//close_thankyou script
    	$j('#close_thankyou').click(function(){
			$j('#alert_success').remove();
		});
		$j('#close_thankyou2').click(function(){
			$j('.alert_error').hide();
		});
    	
    	var uploader1;
    	setTimeout(function() {
            uploader1.init();
            uploader1.bind('FilesAdded', function(up, files) {
                uploader1.start();
            });
        },200);

    	var temp = $j('.validation img').attr('src');
    	$j('.validation img').remove();
    	$j('.validation').append('<img class="xxx" height="50" width="240" src="' + temp + '">');
    	
    	temp = $j('#newaccount-newsletter');
    	$j('#newaccount-newsletter').remove();
    	$j('.newsletter label').prepend(temp);
    	
    	temp = $j('.validation .errors');
    	$j('.validation .errors').remove();
    	$j('.validation').append(temp);
    	$j('.validation .errors').css('float', 'left');
	
       uploader1 = new plupload.Uploader({
            runtimes : 'html5,flash,html4',
            browse_button : 'pickfiles1',
            container : 'container_uploader1',
            max_file_size : '10mb',
            url : '/default/upload/company-pic',
            flash_swf_url : '/plupload/js/plupload.flash.swf',
            silverlight_xap_url : '/plupload/js/plupload.silverlight.xap',
            filters : [
                {title : "Image files", extensions : "jpeg,jpg,gif,png"},
                {title : "Zip files", extensions : "zip"}
            ],
            resize : {width : 320, height : 240, quality : 90}
        });

        uploader1.bind('Error', function(up, err) {
            $j('#filelist').append("<div>Error: " + err.code +
                ", Message: " + err.message +
                (err.file ? ", File: " + err.file.name : "") +
                "</div>"
            );

            up.refresh(); // Reposition Flash/Silverlight
        });
        
        uploader1.bind('PostInit', function() {
            $j('#container_uploader1').css('position', 'static');
        });

        uploader1.bind('FileUploaded', function(up, file, res) {
            var response = $j.parseJSON(res.response);
            $j('#' + file.id + " b").html("100%");

            $j.ajax({
                type: 'POST',
                url: '<?php echo $this->geturl('confirm-business-pic', 'user')?>',
                data: {url:response.ori, 'type':'company'},
                success:function () {
                    $j('#no_logo_selected').hide();
                    $j('#company_logo_cont').show();
                    $j('#company_logo').attr('src',response.url);
                }
            });
        });

		// Client side form validation
		$j('#form_uploader').submit(function(e) {
			var uploader1 = $j('#uploader').pluploadQueue();
	
			// Validate number of uploaded files
			if (uploader1.total.uploaded == 0) {
				// Files in queue upload them first
				if (uploader1.files.length > 0) {
					// When all files are uploaded submit form
					uploader1.bind('UploadProgress', function() {
						if (uploader1.total.uploaded == uploader1.files.length)
							$j('form').submit();
					});
	
					uploader1.start();
				} else
					alert('<?php echo $this->t('You must at least upload one file.')?>');
	
				e.preventDefault();
			}
		});
		
		$j('.remove_photo2').click(function() {

	            $j.post(
	                '<?php echo $this->geturl('delete-logo','user')?>',
	                {},
	                function (data) {
	                        $('#company_logo').attr('src', '');       
							$j('#company_logo_cont').hide();                                 
	                }
	            );

	        return false;
	    });
    	
        ValidateAjax.initialize('form_register_business_info', '/user/validate-register-business');
        $j('#tips').tipsy({html: true, fallback: "<p style='text-align:left'><?php echo $this->t('Company Accounts:<br>- Are specially designed to promote businesses<br>- Auto-list your Company details in AsiaClassified\'s Business Directory - Free<br>- Allows you to designate sub-accounts for your sales team<br>- Provide consolidated reports across all accounts (Primary and Subs)<br>- Access AsiaClassified\'s growing community</p>')?>" });

        //$j('#container_uploader1').css('float', 'none');
        //$j('#container_uploader1').css('position', 'static');

    	<?php if($this->form_register_business_info->isErrors()):?>
    	$j('.alert_error').show();	
		<?php endif;?>
});
    
<?php $this->JQuery()->javascriptCaptureEnd()?>
<?php $this->jQuery()->uiEnable()?>
<?php $to_be_confirmed_ads = new Zend_Session_Namespace('to_be_confirmed_ads');?>
<?php //if (!empty($to_be_confirmed_ads->arr)):?>
    <?php $this->headLink()->appendStylesheet(Ac_Util::getImageBaseUrl('/css/custom_post_ad.css'))?>
<?php //endif;?>
<?php $this->placeholder('container-class')->set('post_ad detail business directory') ?>

<?php if(!empty($_GET['inc'])):?>
    <p class="alert success alert_success" id="alert_success">
    <?php
    $pending = Model_Listing::one(array('us'=>$this->loggedin_user->_id, 'sa'=>Model_Listing::STATUS_BIZ_FORM_INC));
    if(empty($pending)){
	    if($_GET['inc']=='2'){
    		echo $this->t('您的广告尚未发布, 请提供以下信息, 发布广告');
	    } else{
    		echo (!empty($to_be_confirmed_ads->arr)) ? $this->t('请注意 - 您的广告尚未发布, 请提供以下信息, 发布广告') : $this->t('请提供下面信息, 完成您的注册');
	    }
    } else {
    	echo $this->t('请注意 - 您的广告尚未发布, 请提供以下信息, 发布广告');
    }
    ?>
    <a href="#" id="close_thankyou" class="close"><?php echo $this->t('关闭')?></a>
</p>
<?php endif;?>
<?php if(!empty($_GET['post-an-ad-inc'])):?>
    <p class="alert success alert_success" id="alert_success">
	<?php echo $this->t('抱歉, 还没有完成您的注册, 请提供以下信息, 发布广告')?>
	<a href="#" id="close_thankyou" class="close"><?php echo $this->t('Close')?></a>
</p>
<?php endif;?>

<section class="main_section"> 
<?php if (!empty($to_be_confirmed_ads->arr)):?>   
	<section class="nav">      
	<h3><?php echo $this->t('发布信息')?></h3>
        <ol>
          <li><?php echo $this->t('<span>1</span><em>选择分类</em>')?></li>
          <li><?php echo $this->t('<span>2</span><em>创建你的新信息</em>')?></li>
          <li class="selected"><?php echo $this->t('<span>3</span><em>登录</em>')?></li>
        </ol>
      </section>
<?php endif;?>
    <?php if (!empty($to_be_confirmed_ads->arr)):?>
        <section class="alert box">
            <h3><?php echo $this->t('註冊成功')?></h3>
            <p><?php echo $this->t('你可以完成以下')?></p>
            <p class="button"><?php echo $this->t('<a href="#">略過</a>')?></p>
        </section>
    <?php endif;?>
    <h3><?php echo $this->t('完成商業目錄資料')?></h3>
    <section class="form box">
    	<?php //echo $this->form_register_business_info;?>
    	<?php echo $this->form_register_business_info->setAttrib('id', 'form_register_business_info'); ?>
    </section>    
</section>    

<aside class="aside"></aside>
